package com.jwcao.common.cast.operation.access;

import com.jwcao.common.scan.object.ScanClass;
import com.jwcao.common.scan.object.ScanField;
import lombok.Getter;

/**
 * name: MethodAccessOperation description: TODO
 *
 * @author caojingwei date: 2023/3/23 16:18
 */
@Getter
public class MethodAccessOperation extends AccessOperation {

    private final ScanClass sourceClass;
    private final String methodName;

    public MethodAccessOperation(ScanClass sourceClass, ScanField targetField, String methodName) {
        super(targetField);
        this.sourceClass = sourceClass;
        this.methodName = methodName;
    }

    @Override
    public Object execute(Object object) {
        return sourceClass.invokeMethod(object, methodName);
    }
}
